package com.kcwl.carrier.infrastructure.repository.persostence;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kcwl.carrier.domain.repository.ICarrierGroupRepository;
import com.kcwl.carrier.infrastructure.repository.mapper.CarrierGroupMapper;
import com.kcwl.carrier.infrastructure.repository.po.CarrierGroupPO;
import com.kcwl.carrier.interfaces.command.IdCommand;
import com.kcwl.carrier.interfaces.query.IdQuery;
import com.kcwl.ddd.domain.entity.KcPage;
import com.kcwl.ddd.domain.repository.BaseRepositoryImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author 刘旭超
 * @date 2022年07月11日 16:33
 * @Description
 */
@Service
public class CarrierGroupRepositoryImpl extends BaseRepositoryImpl<CarrierGroupMapper, CarrierGroupPO> implements ICarrierGroupRepository {

    @Resource
    private CarrierGroupMapper groupMapper;


    @Override
    public Class<CarrierGroupPO> getPoClass() {
        return CarrierGroupPO.class;
    }


    @Override
    public KcPage<CarrierGroupPO> groupList(IdQuery query) {
        QueryWrapper<CarrierGroupPO> wrapper = new QueryWrapper<>();
        wrapper.eq("create_user_id", query.getId());
        Page<CarrierGroupPO> page = groupMapper.selectPage(new Page<>(query.getCurPagerNo(), query.getPageSize()), wrapper);
        return new KcPage<>(page.getTotal(), page.getCurrent(), page.getSize(), page.getRecords());
    }
}
